<?php
    chdir('../../');
    require('inc/header.php');
    
    if(isset($_SESSION['user']['uid'])) {
        $uid = (int)$_SESSION['user']['uid'];
        $user = new AnyUser($uid);
        if($user->getUid() > 0) {
            $db = Database::getInstance();
            $term = $_GET['term'];
            $db->query("SELECT
                            uid, name, surname, login
                        FROM
                            users
                        WHERE
                            name like '$term%' OR
                            surname like '$term%' OR
                            login like '%$term%'
                        LIMIT 10
                        ");
            $return = array();
            foreach($db->getObjectArray() as $key => $obj) {
                $return[] = array("uid"=>$obj->uid, "label"=>$obj->name . ' ' . $obj->surname . ' (' . $obj->login . ')');
            }
            die(json_encode($return));
        }
    }
?>
